package com.gexiaobao.pigeon.ui.adapter

import android.widget.ImageView
import androidx.appcompat.widget.AppCompatImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.flyjingfish.openimagelib.OpenImage
import com.flyjingfish.openimagelib.enums.MediaType
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.PigeonFosterBean
import com.gexiaobao.pigeon.app.util.ImageLoaderManager
import com.gexiaobao.pigeon.databinding.ItemTnetPictureBinding

/**
 * @Author      : hxw
 * @Date        : 2024/6/14 14:56
 * @Describe    :
 */
class AdapterTentPicture(data: ArrayList<PigeonFosterBean.ListData>) :
    BaseQuickAdapter<PigeonFosterBean.ListData, DataBindBaseViewHolder>(R.layout.item_tnet_picture, data) {
    override fun convert(holder: DataBindBaseViewHolder, item: PigeonFosterBean.ListData) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemTnetPictureBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        val ivTentPic = holder.getView<AppCompatImageView>(R.id.ivTentPic)
        ImageLoaderManager.loadRoundImageOrEmpty(context, item.loftPicPath, ivTentPic, 10, R.mipmap.icon_visit_list_empty)

        ivTentPic.setOnClickListener {
            openBigImage(ivTentPic, item.loftPicPath)
        }
    }

    private fun openBigImage(ivTentPic: AppCompatImageView, loftPicPath: String) {
        OpenImage.with(context)
            .setClickImageView(ivTentPic)
            .setSrcImageViewScaleType(ImageView.ScaleType.CENTER_CROP, true)
            .setImageUrl(loftPicPath, MediaType.IMAGE).show()
    }

}